

clear all

set more off 





global estimators xtreg

local max_p 2

***plotting
local title_left Civil War
local title_right Armed Conflict

local left_solid_name OLS
local left_dash_name Logit

local right_solid_name OLS
local right_dash_name Logit

clear
use model_names_nofe
levelsof controls, local(levels) 
clear


*foreach on_or_in in onset incidence {
foreach on_or_in in onset {

forval p = `max_p' / `max_p' {

if `p' == 1 {
	local what civilwar
}
if `p' == 2 {
	local what armedconflict
}

*foreach var in overall within {
foreach var in within {

if "`var'" == "overall" {
	local ei OLS
}
if "`var'" == "within" {
	local ei Logit
}

graph drop _all

foreach j in controls {	

	foreach x in $estimators {

		display "`j'"
		display "`k'"
		display "`x'"

		clear

			*graph of war
		use output/for_roc_onlyintersection_nofe_`on_or_in'`p'

		rename modelname model
		sort model
		merge model using model_names_nofe
		sort id fpr tpr
			
		

		graph drop _all
			
		local l = 1
			
		foreach k of local levels {
		
			local doit 0
		
			if "`k'" == "chadefauxshort"  {
				local nameit Keyword Count Only
				local doit 1
				local num 7
			}
			if "`k'" == "ourswith"  {
				local nameit Years since conflict
				local doit 1
				local num 8
			}
			
			if "`k'" == "fixedeffect"  {
				local nameit Fixed effect
				local doit 0
				
			}
			if "`k'" == "chadefaux"  {
				local nameit Keyword Count
				local doit 1
				local num 6
			}
			if "`k'" == "ajps"  {
				local nameit Economics and Political
				local doit 1
				local num 3
			}
			if "`k'" == "ward"  {
				local nameit Events
				local doit 1
				local num 4
			}
			if "`k'" == "eventsshort"  {
				local nameit Events only
				local doit 1
				local num 5
			}
			if "`k'" == "pillars"  {
				local nameit Shocks and Institutions
				local doit 1
				local num 2
			}
			if "`k'" == "rain"  {
				local nameit Rainfall
				local doit 1
				local num 1
			}
			

			sum auc if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 0
			if `r(N)' > 0 & `doit' == 1 {
				local auc1 = substr(string(round(`r(max)',.01)), 1, 3)
				sum auc if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'"  & way == 1
				local auc2 = substr(string(round(`r(max)',.01)), 1, 3)

				twoway (line tpr fpr if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 0, lwidth(medthick)  lpattern(solid)  sort) ///
				(line tpr fpr if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 1, lwidth(medthick) lpattern(dash)  sort) ///
				 (line fpr fpr if what == "overall" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 1, color(gs10) lpattern(dash) sort), ///
				subtitle("`nameit'", color(black)) ytitle("") xtitle("")  xlabel(,grid) ///
				legend( order(1 "Benchmark" 2 "Topics") size(small)) ///
				plotregion(fcolor(white)) graphregion(fcolor(white))   ///	
				caption( "AUC: Benchmark `auc1', Topics `auc2'", size(medium) color(black) ring(0)  placement(se)) ///
				name(fig`num')
*aspectratio(1)

				local l = `l' + 1
				
			}


		}
		
		}
		

	}
}



}

}


**********

foreach on_or_in in onset {

forval p = `max_p' / `max_p' {

if `p' == 1 {
	local what civilwar
}
if `p' == 2 {
	local what armedconflict
}

*foreach var in overall within {
foreach var in within {

if "`var'" == "overall" {
	local ei OLS
}
if "`var'" == "within" {
	local ei Logit
}

*graph drop _all

foreach j in controls+thetas {	

	foreach x in $estimators {

		display "`j'"
		display "`k'"
		display "`x'"

		clear

			*graph of war
		use output/for_roc_onlyintersection_nofe_`on_or_in'`p'

		rename modelname model
		sort model
		merge model using model_names_nofe
		sort id fpr tpr
			
		

		*graph drop _all
			
		local l = 1
			
		foreach k in ourswith {
		
			local doit 0
		

			if "`k'" == "ourswith"  {
				local nameit Topics & years since conflict
				local doit 1
				local num 9
			}
			
		
						sum auc if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 0
			if `r(N)' > 0 & `doit' == 1 {
				local auc1 = substr(string(round(`r(max)',.01)), 1, 3)
				sum auc if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'"  & way == 1
				local auc2 = substr(string(round(`r(max)',.01)), 1, 3)

				twoway (line tpr fpr if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 0, lwidth(medthick)  lpattern(solid)  sort) ///
				(line tpr fpr if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 1, lwidth(medthick) lpattern(dash)  sort) ///
				 (line fpr fpr if what == "overall" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 1, color(gs10) lpattern(dash) sort), ///
				subtitle("`nameit'", color(black)) ytitle("") xtitle("")  xlabel(,grid) ///
				legend( order(1 "Benchmark" 2 "Topics") size(small)) ///
				plotregion(fcolor(white)) graphregion(fcolor(white))   ///	
				caption( "AUC: Benchmark `auc1', Topics `auc2'", size(medium) color(black) ring(0)  placement(se)) ///
				name(fig`num')


				local l = `l' + 1
				
			}


		}
		
		}
		
				
		grc1leg fig1 fig2 fig3 fig4 fig5 fig6 fig7 fig8 fig9 , legendfrom(fig1)  title("", color(black)  size(small)) subtitle("", color(black) size(small)) plotregion(fcolor(white)) graphregion(fcolor(white)) 

		graph export output/FigE18.eps ,replace
		
	}
}



}

}








